# 对象层
from selenium.webdriver.common.by import By

from LoginCart.base.basePage import BasePage, BaseHandle


class PageLogin(BasePage):
    def __init__(self):
        super().__init__()
        self.username=By.ID,"username"
        self.password=By.ID,"password"
        self.code=By.CSS_SELECTOR,"[class='text_uspa check_cum']>[class='text_cmu']"
        self.login=By.CSS_SELECTOR,".J-login-submit"

    def find_username(self):
        return self.get_element(self.username)

    def find_password(self):
        return self.get_element(self.password)

    def find_code(self):
        return self.get_element(self.code)

    def find_login_btn(self):
        return self.get_element(self.login)

# 操作层
class HandleLogin(BaseHandle):
    def __init__(self):
        self.page_login=PageLogin()

    def handle_username(self,username):
        self.input_text(self.page_login.find_username(),username)

    def handle_password(self,password):
       self.input_text(self.page_login.find_password(),password)

    def handle_code(self,code):
        self.input_text(self.page_login.find_code(),code)

    def handle_login_btn(self):
        self.page_login.find_login_btn().click()

# 业务层
class ProxyLogin:
    def __init__(self):
        self.handle_login=HandleLogin()

    def login_page(self,username,password,code):
        self.handle_login.handle_username(username)
        self.handle_login.handle_password(password)
        self.handle_login.handle_code(code)
        self.handle_login.handle_login_btn()